package com.eascs.web.p2p.action;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.app.dao.PageResult;
import com.eascs.common.util.UrlUtil;
import com.eascs.p2p.common.service.IInvestObjectService;
import com.eascs.p2p.common.vo.InvestObjectVO;
import com.eascs.p2p.common.vo.ModelResult;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.view.BaseRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.site.view.button.AjaxButton;
import com.eascs.site.view.button.Button;
import com.eascs.site.view.button.RedirectButton;
import com.eascs.site.view.button.ShowButtonFilter;
import com.eascs.tag.MenuTag;
import com.eascs.web.p2p.common.BaseMasterViewController;

@Controller
@RequestMapping("/bid")
public class DirectInsuranceController extends BaseMasterViewController {

	@Reference
	IInvestObjectService investObjectService;
	

	@Override
	public void preHandle() {
		super.preHandle();
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "BidAdmin");
	}



	
	
	/**
	 * @Title: directInsurance
	 * @Description: 直投宝管理
	 * @author 张庆奇
	 * @param vo
	 * @return
	 * @return String
	 * @throws
	 * @date 2016年7月8日 上午11:21:00
	 */
	@RequestMapping(value = "/directInsurance")
	public String directInsurance(InvestObjectVO vo) {
		vo.setType(2);
		vo.setPageSize(10);
		ModelResult<PageResult<Object[]>> model = investObjectService.findPageInvestObjectEntity(vo);
		PageResult<Object[]> pageResult=new PageResult<Object[]>();
		if(model.isSuccess()){
			 pageResult = model.getModel();
		} 
			
		

		String[] titles = {  "项目编号","项目名称","项目类型", "借款人姓名","借款金额", "年化率","借款期限", "失效时间" ,"融资进度" ,"状态"};
		
		
		RedirectButton detailButton=	new RedirectButton("  详情", "/bid/op_bid?opType=show&type=2&id=");
		
		AjaxButton Button1=new AjaxButton("  终止", "/bidRest/verifyBid?op=over&id=");
		Button1.setShowButtonFilter(new ShowButtonFilter() {
			
			@Override
			public boolean filter(Object param) {
				Object[] params=(Object[]) param;
				return "融资中".equals(params[10]);
			}
		});
		
		
		AjaxButton Button2=new AjaxButton("  放款", "/bidRest/loanMoney?id=");
		Button2.setShowButtonFilter(new ShowButtonFilter() {
			
			@Override
			public boolean filter(Object param) {
				Object[] params=(Object[]) param;
				return "已满标".equals(params[10]);
			}
		});
		
	/*	AjaxButton Button3=new AjaxButton("还款", "/bidRest/backMoney?id=");
		Button3.setShowButtonFilter(new ShowButtonFilter() {
			
			@Override
			public boolean filter(Object param) {
				Object[] params=(Object[]) param;
				return "还款中".equals(params[10]);
			}
		});
		
		
		AjaxButton Button4=new AjaxButton("还款明细", "/refundRest/plan?bidId=");
		Button4.setShowButtonFilter(new ShowButtonFilter() {
			
			@Override
			public boolean filter(Object param) {
				Object[] params=(Object[]) param;
				return "还款中".equals(params[10])||"已结清".equals(params[10])||"还款异常".equals(params[10])||"逾期结清".equals(params[10]);
			}
		});*/
		AjaxButton voteRecordButton=new AjaxButton("投资记录                   ", "/bidRest/record/?id=");
		Button[] buttons = new Button[] {detailButton,Button1,Button2,voteRecordButton};
		String pageUrl = "/bid/directInsurance";

		pageUrl = UrlUtil.appendUrl(pageUrl, "billCode", vo.getBillCode());
		pageUrl = UrlUtil.appendUrl(pageUrl, "title", vo.getTitle());
		pageUrl = UrlUtil.appendUrl(pageUrl, "groupTeam", vo.getGroup());
		pageUrl = UrlUtil.appendUrl(pageUrl, "beginCreateTime", vo.getBeginCreateTime());
		pageUrl = UrlUtil.appendUrl(pageUrl, "endCreateTime", vo.getEndCreateTime());
		pageUrl = UrlUtil.appendUrl(pageUrl, "loaneeName", vo.getLoaneeName());
		pageUrl = UrlUtil.appendUrl(pageUrl, "status", vo.getStatus());
		pageUrl = UrlUtil.appendUrl(pageUrl, "showPage", "");
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, pageUrl );
		paginationInfo.setBuildPagingNavigation(true);
		paginationInfo.setFirstRenderColumnIndex(1);
		paginationInfo.setMoreButtons(buttons);
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("vo", vo);
		ModelResult<InvestObjectVO> voModel = investObjectService.getNotVerifyNum(vo);
		InvestObjectVO investObjectVO =null;
		if(model.isSuccess()){
			investObjectVO = voModel.getModel();
		}
		
		ViewContext.put("investObjectVO", investObjectVO);
		BaseRestResult.refresh();
		return "/bid/direct_insurance";
	}
	
	

	
	
}
